//
//  BluetoothManager.h
//  BluetoothProject
//
//  Created by JianWei Chen on 16/9/5.
//  Copyright © 2016年 JianWei Chen. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>





@class DTCDeviceModel;

@protocol DTCBluetoothManagerDelegate <NSObject>

@optional
/*
 设备notify数据返回
 */
- (void)dtcBluetoothManagerWriteDataBack:(NSData *)data andNotifyCharacteristic:(NSString *)characterValue sendByDevice:(DTCDeviceModel *)deviceModel;

/*
 设备read数据返回
 */
- (void)dtcBluetoothManagerReadDataBack:(NSData *)data andNotifyCharacteristic:(NSString *)characterValue sendByDevice:(DTCDeviceModel *)deviceModel;

/*
 设备列表发生改变的时候返回
 */
- (void)dtcBluetoothManagerSearchDeviceChange:(NSArray *)deviceList;

/*
 设备连接成功
 */
- (void)dtcBluetoothManagerConnectSuccessByDevice:(DTCDeviceModel *)deviceModel;

/*
 设备连接断开
 */
- (void)dtcBluetoothManagerDisConnectByDevice:(DTCDeviceModel *)deviceModel;

/**
 设备连接失败
 */
- (void)dtcBluetoothManagerConnectFailByDevice:(DTCDeviceModel *)deviceModel error:(NSError *)error;

/**
 发现特征
 */
- (void)dtcBluetoothManagerDiscoverCharacteristicSerice:(DTCDeviceModel *)deviceModel characeristic:(CBCharacteristic *)characteristic error:(NSError *)error;

/*
 当前中心的状态
 */
- (void)dtcBluetoothManagerCentralManagerState:(CBManagerState)state;

@end
/**
 蓝牙管理类
 */
@interface DTCBluetoothManager : NSObject

@property(assign, nonatomic) CBManagerState blueState;//蓝牙中心状态
@property(nonatomic, strong) NSMutableArray *scanDeviceList;//处于搜索范围内的设备
@property(strong, nonatomic) NSMutableArray *connectedDeviceList;//处于连接状态中的设备
@property (nonatomic, weak) id <DTCBluetoothManagerDelegate> delegate;//数据反馈代理

+(instancetype)shareInstance;

/*
 读写方法
 */
- (void)writeValueToDevice:(DTCDeviceModel *)device writeData:(NSData *)data characteristicValue:(NSString *)characterValue;

- (void)readValueFromDevice:(DTCDeviceModel *)device characteristicValue:(NSString *)characterValue;

/*
 蓝牙设备操作
 */
- (void)connectDevice:(DTCDeviceModel *)device;

- (void)disconnectDevice:(DTCDeviceModel *)device;

/*
 蓝牙管理操作
 */
- (void)scanAroundDevice;

- (void)cancelScanDevice;

- (void)cancelAllDeviceConnection;

#pragma mark - 通常都会进行以下几项的设置

/**
 设置设备过滤条件,根据服务的UUID进行设备过滤，也可以是根据设定条件进行过滤

 @param serviceList 根据服务过滤发现设备的服务 UUID数组
 @param filter 设置过滤设备的条件
 */
- (void)setFilterDeviceByServiceUUID:(NSArray *)serviceList onDiscoverPeripherals:(BOOL (^)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI))filter;

/**
 设置进行广播的特征值

 @param characteristicValueList write notify通道UUID数组
 */
- (void)setWriteNotifyCharacteristicValue:(NSArray *)characteristicValueList;


/**
 设置进行Read广播的特征值

 @param characteristicValueList read notify通道UUID数组
 */
- (void)setReadNotifyCharacteristicValue:(NSArray *)characteristicValueList;
@end
